#include<bits/stdc++.h>
using namespace std;
int n,q;
char s[1000005];
int qzh[1000005];
int hzh[1000005];
int treeq[4000005],treeh[4000005];
int qmaxx[4000005];
int idq[4000005],idh[4000005];
int father[1000005][22],need[1000005][22];
void pushup(int l,int r,int x)
{
    if(treeq[2*x]<treeq[2*x+1])
    {
        treeq[x]=treeq[2*x];
        idq[x]=idq[2*x];
    }
    else
    {
        treeq[x]=treeq[2*x+1];
        idq[x]=idq[2*x+1];
    }

    if(treeh[2*x]<treeh[2*x+1])
    {
        treeh[x]=treeh[2*x];
        idh[x]=idh[2*x];
    }
    else
    {
        treeh[x]=treeh[2*x+1];
        idh[x]=idh[2*x+1];
    }
    qmaxx[x]=max(qmaxx[2*x],qmaxx[2*x+1]);
}
void build(int l,int r,int x)
{
    if(l==r)
    {
        treeq[x]=qzh[l];
        idq[x]=l;
        qmaxx[x]=qzh[l];
        treeh[x]=hzh[l];
        idh[x]=l;
        return;
    }
    int mid=(l+r)>>1;
    build(l,mid,2*x);
    build(mid+1,r,2*x+1);
    pushup(l,r,x);
}
int minn,nowid;
void queryq(int l,int r,int ql,int qr,int x)
{
    if(l==ql&&r==qr)
    {
        if(treeq[x]<minn)
        {
            minn=treeq[x];
            nowid=idq[x];
        }
        return;
    }
    int mid=(l+r)>>1;
    if(ql<=mid)
    {
        queryq(l,mid,ql,min(mid,qr),2*x);
    }
    if(qr>mid)
    {
        queryq(mid+1,r,max(ql,mid+1),qr,2*x+1);
    }
}
void queryh(int l,int r,int ql,int qr,int x)
{
    if(ql>qr)
    {
        return;
    }
    if(l==ql&&r==qr)
    {
        if(treeh[x]<minn)
        {
            minn=treeh[x];
        }
        return;
    }
    int mid=(l+r)>>1;
    if(ql<=mid)
    {
        queryh(l,mid,ql,min(mid,qr),2*x);
    }
    if(qr>mid)
    {
        queryh(mid+1,r,max(ql,mid+1),qr,2*x+1);
    }
}
int queryy(int l,int r,int ql,int qr,int key,int x)
{
    if(l==ql&&r==qr)
    {
        if(l==r)
        {
            if(treeq[x]<key)
            {
                return l;
            }
            else
            {
                return n+1;
            }
        }
        int mid=(l+r)>>1;
        if(treeq[2*x]<key)
        {
            return queryy(l,mid,l,mid,key,2*x);
        }
        if(treeq[2*x+1]<key)
        {
            return queryy(mid+1,r,mid+1,r,key,2*x+1);
        }
        return n+1;
    }
    int mid=(l+r)>>1;
    if(ql<=mid)
    {
        int tt=queryy(l,mid,ql,min(qr,mid),key,2*x);
        if(tt!=n+1)
        {
            return tt;
        }
    }
    if(qr>mid)
    {
        int tt=queryy(mid+1,r,max(mid+1,ql),qr,key,2*x+1);
        if(tt!=n+1)
        {
            return tt;
        }
    }
    return n+1;
}
int querymax(int l,int r,int ql,int qr,int x)
{
    if(qr<ql)
    {
        return -0x3f3f3f3f;
    }
    if(l==ql&&r==qr)
    {
        return qmaxx[x];
    }
    int mid=(l+r)>>1;
    int re=-0x3f3f3f3f;
    if(ql<=mid)
    {
        re=max(re,querymax(l,mid,ql,min(qr,mid),2*x));
    }
    if(qr>mid)
    {
        re=max(re,querymax(mid+1,r,max(ql,mid+1),qr,2*x+1));
    }
    return re;
}
int main()
{
    freopen("good.in","r",stdin);
    freopen("good.out","w",stdout);
    cin>>n>>q;
    for(int i=1;i<=n;i++)
    {
        cin>>s[i];
    }
    for(int i=1;i<=n;i++)
    {
        if(s[i]=='1')
        {
            qzh[i]=qzh[i-1]+1;
        }
        else
        {
            qzh[i]=qzh[i-1]-1;
        }
    }
    for(int i=n;i>=1;i--)
    {
        if(s[i]=='1')
        {
            hzh[i]=hzh[i+1]+1;
        }
        else
        {
            hzh[i]=hzh[i+1]-1;
        }
    }
    build(1,n,1);
    for(int i=0;i<=20;i++)
    {
        father[n+1][i]=n+1;
        need[n+1][i]=-0x3f3f3f3f;
        father[n+2][i]=n+1;
        need[n+2][i]=-0x3f3f3f3f;
    }
    for(int i=n;i>=1;i--)
    {
        int noww=queryy(1,n,i,n,qzh[i-1],1);
        //cout<<"??"<<i<<" "<<noww<<endl;
        if(noww==n+1)
        {
            father[i][0]=n+1;
            need[i][0]=-0x3f3f3f3f;
            for(int j=1;j<=20;j++)
            {
                father[i][j]=father[father[i][j-1]+1][j-1];
                need[i][j]=max(need[i][j-1],need[father[i][j-1]+1][j-1]);
            }
        }
        else
        {
            father[i][0]=noww;
            //cout<<"!!"<<i<<" "<<noww-1<<" "<<querymax(1,n,i,noww-1,1)<<" "<<qzh[i-1]<<endl;
            need[i][0]=querymax(1,n,i,noww-1,1)-qzh[i-1];
            for(int j=1;j<=20;j++)
            {
                father[i][j]=father[father[i][j-1]+1][j-1];
                need[i][j]=max(need[i][j-1],need[father[i][j-1]+1][j-1]);
            }
        }
    }
    int l,r;
    int anss=0;
    for(int i=1;i<=q;i++)
    {
        int ans=0;
        cin>>l>>r;
        minn=0x3f3f3f3f;
        nowid=n+1;
        queryq(1,n,l,r,1);
        //cout<<"::"<<nowid<<endl;
        if(minn<=qzh[l-1])
        {
            int maxx=0;
            ans+=qzh[l-1]-minn;
            int pp=l-1;
            for(int j=20;j>=0;j--)
            {
                if(father[pp+1][j]<=nowid)
                {
                    maxx=max(maxx,need[pp+1][j]);
                    pp=father[pp+1][j];
                }
            }
            if(pp!=l-1)
            {
                maxx=max(maxx,1);
            }
            if(pp!=nowid)
            {
                maxx=max(maxx,querymax(1,n,pp+1,nowid,1)-qzh[pp]);
            }
            //cout<<pp<<" "<<maxx<<endl;
            //cout<<"!!"<<ans<<endl;
            minn=0x3f3f3f3f;
            queryh(1,n,nowid+1,r,1);
            int add=max(hzh[r+1]-minn,0);
            if(hzh[nowid+1]-hzh[r+1]+add-maxx>0)
            {
                maxx=0;
            }
            else
            {
                maxx=maxx-(hzh[nowid+1]-hzh[r+1]);
            }
            //cout<<"??"<<maxx<<endl;
            ans+=max(hzh[r+1]-minn,max(maxx,add));
        }
        else
        {
            minn=0x3f3f3f3f;
            queryh(1,n,l,r,1);
            ans=max(ans,hzh[r+1]-minn);
        }
        //cout<<ans<<endl;
        anss^=ans;
    }
    cout<<anss;
    return 0;
}
